define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_consume_log/index' + location.search,
                    add_url: 'user_consume_log/add',
                    // edit_url: 'user_consume_log/edit',
                    del_url: 'user_consume_log/del',
                    multi_url: 'user_consume_log/multi',
                    import_url: 'user_consume_log/import',
                    table: 'user_consume_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'consume_id',
                sortName: 'consume_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'consume_id', title: __('id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'shop_name', title: __('Shop_name'), operate: 'LIKE'},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'consume_type', title: __('Consume_type'), searchList: {3: __('团购'),2: __('线上买单'),1: __('折扣买单'), 0: __('线下买单')}, formatter: Table.api.formatter.status},
                        {field: 'cps_type', title: __('Cps_type'), searchList: {7: __('淘宝'),6: __('抖音'),5: __('滴滴'),4: __('饿了么'),3: __('美团'),2: __('唯品会'),1: __('拼多多'), 0: __('京东'),'-1': __('团购')}, formatter: Table.api.formatter.status},
                        {field: 'is_to_account', title: __('Is_to_account'), searchList: {1: __('已到账'), 0: __('未到账')}, formatter: Table.api.formatter.status},
                        {field: 'account_time', title: __('Account_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                        {field: 'total_commission', title: __('Total_commission'), operate:'BETWEEN'},
                        {field: 'commission', title: __('Commission'), operate:'BETWEEN'},

                        {field: 'order_status_name', title: __('Order_status_name'), operate: 'LIKE'},
                        {field: 'is_refund', title: __('Is_refund'), searchList: {1: __('已退款'), 0: __('未退款')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'send_total_commission', title: __('Send_total_commission'), operate:'BETWEEN'},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
